var app = getApp()
var Utils = require('../../../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    textareatxt: "",
    popif: false,
    inquiry: "",
    argeen: true,
    steps: ["上传处方", "完善信息", "选择药品", "医生开药"],
    upload_picture_list: [],
    stepnum: 0,
    typedate: 0,
    speedlist: [{
        tit: "祛斑/去痘印",
        text: "祛斑/去痘印"
      },
      {
        tit: "痔疮/痘痘",
        text: "痔疮/痘痘"
      },
      {
        tit: "去黑头",
        text: "去黑头"
      },
      {
        tit: "脚气",
        text: "脚气"
      },
      {
        tit: "湿疹",
        text: "湿疹"
      },
      {
        tit: "避孕",
        text: "避孕"
      },

    ]
  },
  //调单提交
  infomationbtn(e) {
    var that = this
    var inquiry = that.data.inquiry
    var upload_picture_list = that.data.upload_picture_list
    var typedate = that.data.typedate
    var key_words = that.data.key_words
    var ifshop = that.data.ifshop
    if (that.data.inquiry == '4') {
      var vals = e.detail.value.zhengzhuang;
      if (upload_picture_list.length == 0) {
        wx.showToast({
          title: '请上传处方凭证',
          icon: 'none'
        })
        return false
      }
    }
    if (that.data.inquiry == '3') {
      var vals = e.detail.value;
    }
    console.log(e)
    var arr = {
      'text': vals,
      'text2': '',
      'timleng': '',
      'upload_picture_list': upload_picture_list,
      'typedate': typedate
    }
    var conets = JSON.stringify(arr)
    if (e.detail.value.zhengzhuang.zhengzhuang == "") {
      wx.showToast({
        title: '提问至少10字',
        icon: 'none'
      })
    } else {
      let upload_picture_list = this.data.upload_picture_list
      //提交
      if (ifshop == '1') {
        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2];
        prevPage.setData({
          typedate: that.data.typedate,
          conets: conets
        })
        wx.navigateBack({
          delta: 1,
        })
      } else {
        wx.navigateTo({
          url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?key_words=' + key_words + '&conets=' + conets + '&inquiry=' + inquiry,
        })
      }

    }
  },
  // 常见疾病
  chooseLabel(e) {
    let i = e.currentTarget.dataset.dex,
      arrs = this.data.speedlist
    this.setData({
      textareatxt: arrs[i].text
    })
  },
  //关闭模态框
  closepop() {
    this.setData({
      popif: false
    })
  },
  nopingzheng() {
    this.setData({
      popif: true
    })
  },
  //开方
  textarr(e) {
    var that = this
    var zhengzhuang = e.detail.value
    var cursor = e.detail.value.cursor
    that.setData({
      zhengzhuang: zhengzhuang,
      cursor: cursor
    })
  },
  navUrgent() {
    var key_words = this.data.key_words
    var that = this
    var inquiry = that.data.inquiry
    var upload_picture_list = that.data.upload_picture_list
    var typedate = that.data.typedate
    var key_words = that.data.key_words
    var ifshop = that.data.ifshop
    console.log(that.data.cursor)
    if (that.data.inquiry == '4') {
      var vals = that.data.zhengzhuang;
    }
    if (that.data.inquiry == '3') {
      var vals = that.data.zhengzhuang;
    }
    if (that.data.cursor == "" || that.data.cursor == 0) {
      wx.showToast({
        title: '提问至少10字',
        icon: 'none'
      })
      return false
    }
    var arr = {
      'text': vals,
      'text2': '',
      'timleng': '',
      'upload_picture_list': upload_picture_list,
      'typedate': typedate
    }
    var conets = JSON.stringify(arr)
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/huanzhexinxi/huanzhexinxi?key_words=' + key_words + '&conets=' + conets + '&inquiry=' + inquiry,
    })
  },
  //删除图片
  deleteimg: function (e) {
    var that = this;
    var i = e.currentTarget.dataset.index;
    var imgArr = that.data.upload_picture_list;
    imgArr.splice(i, 1);
    that.setData({
      upload_picture_list: imgArr,
      typedate: 0
    })
  },
  // 上传图片
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;

    wx.chooseImage({
      count: 5-that.data.upload_picture_list.length,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res)
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  // 是否同意协议
  radioChange() {
    this.setData({
      argeen: !this.data.argeen
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    var bgc = wx.getStorageSync('color')
    if (options.ifshop) {
      that.setData({
        ifshop: options.ifshop
      })
    }
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var key_words = options.key_words
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        that.setData({
          url: res.data,
        })
      }
    })
    this.setData({
      inquiry: options.inquiry,
      key_words: key_words,
      bgc: bgc
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})